<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
</head>
<body>
<button onclick="createQrcode()">点我生成网二维码</button>
<button onclick="downloadQrcode()">点我下载二维码</button>
<div id="qrcode"></div>
</body>
</html>
<script>
    function createQrcode(){
        qrcode1 = new QRCode(document.getElementById("qrcode"), {
            text: "http://static.runoob.com/assets/qrcode/qrcode.min.js",
            width: 300, //生成的二维码的宽度
            height: 300, //生成的二维码的高度
            colorDark : "#000000", // 生成的二维码的深色部分
            colorLight : "#ffffff", //生成二维码的浅色部分
            correctLevel : QRCode.CorrectLevel.H
        });
    }
    function downloadQrcode(){
        var qrcode = document.getElementById('qrcode');
        var img = qrcode.getElementsByTagName('img')[0];
        var link = document.createElement("a");
        var url = img.getAttribute("src");
        link.setAttribute("href",url);
        link.setAttribute("download",'123.png');
        link.click();
    }
</script>
